<template>
    <view id="welcome" >
        <view class="loading-part" v-if="isLoading">

        </view>
        <view class="main">
            <view class="tip">{{title}}</view>
            <view class="btn-group" v-if="loginFlag">
                <button @click="goToPage" size="mini" class="btn">登陆系统</button>
            </view>
            <view class="btn-group" v-else>
                <button @click="goToPage" size="mini" class="btn">重新登陆</button>
                <button @click="gotoSys" size="mini" class="btn">进入系统</button>
            </view>
        </view>
    </view>
</template>
<script>
    import { getMSName } from '@/common/api.js'
    export default {
        components: {

        },
        data() {
            return {
                title:'欢迎使用棋协系统',
                navigateFlag: false,
                isLoading:true,
                loginFlag:true,
                selectedUnder:''
            }
        },
        methods: {
            goToPage() {
                if (this.navigateFlag) {
                    return;
                }
                this.navigateFlag = true;
                uni.navigateTo({
                    url: '/pages/home/login?under='+this.selectedUnder
                })
                setTimeout(() => {
                    this.navigateFlag = false;
                }, 200)
            },
            gotoSys(){
                if (this.navigateFlag) {
                    return;
                }
                this.navigateFlag = true;
                uni.navigateTo({
                    url: '/pages/home/index'
                })
                setTimeout(() => {
                    this.navigateFlag = false;
                }, 200)
            },
            getName(){
                getMSName({
                    key:this.selectedUnder
                }).then((res)=>{
                    const data = res.data;
                    if(data.errcode==0){
                        this.title=data.data;
                    }
                })
            }
        },
        onLoad(options) {
            let under = options.under || '';
            this.selectedUnder = options.key || '';
            if(process.env.NODE_ENV === 'development'){
                /*龙蛇棋类*/
                this.selectedUnder = 'fr5y501gjppumqne';
                under = '33';
                /*辽宁*/
                // this.selectedUnder = '2ht01pt36xqwvezl';
                // under = '4102';
            }
            if(this.selectedUnder){
                uni.setStorageSync('_underKey_',this.selectedUnder);
                this.getName();
            }else{
                uni.setStorageSync('_underKey_','');
            }
            if(under){
                if(under!=uni.getStorageSync('_under_')){
                    uni.removeStorageSync('token');
                    this.loginFlag=true;
                }
                uni.setStorageSync('_under_',under)
            }else{
                uni.removeStorageSync('token');
                this.loginFlag=true;
            }
            uni.showLoading({
                title: '加载中'
            });
            console.log(this.selectedUnder);
            console.log(under);
            setTimeout(()=>{
                this.isLoading=false;
                uni.hideLoading();
            },500)
        },
        onShow() {
            if(uni.getStorageSync('token')){
                this.loginFlag=false;
            }

        }
    }
</script>

<style lang="scss">
    page{
        background: #fff;
    }
    #welcome {
        position: relative;
        height: 100%;
        .loading-part{
            position: absolute;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0;
            background: #fff;
            z-index: 100;
        }
        .main{
            .tip{
                font-size: 60rpx;
                text-align: center;
                font-weight: bold;
                height: 50vh;
                display: flex;
                justify-content: center;
                align-items: center;

            }
            .btn-group{
                text-align: center;
                .btn{
                    display: block;
                    margin-top: 40rpx;
                    border-radius: 50rpx;
                    color: #fff;
                    background: #1A66FF;
                    width: 220rpx;
                }
            }
        }
    }
</style>
